package com.littlerpc.proxy.util;


import com.littlerpc.common.util.*;

import java.lang.annotation.Annotation;
import java.net.URLClassLoader;
import java.util.Set;

/**
 *
 * @author ChengPeng
 * @date 2017/6/26
 */
public class ProxyUtil {

    public static Set<Class<?>> getClassesWithAnnotationClass(Class<? extends Annotation> annotation, String[] sacnPackages) {

        ClassFilter filter = new ClassFilter() {
            @Override
            public boolean accept(Class clazz) {
                return clazz.getAnnotation(annotation) != null;
            }
        };


        ClassLoader classLoader = ClassUtils.getClassLoader();
        if(classLoader instanceof URLClassLoader) {
            return WebScanner.scanPackages(sacnPackages, filter);
        }else {
            return LauncherScanUtil.scanPackages(sacnPackages, filter);
        }
    }
}
